/******************************************************
 * Copyright (c) 2012, LIJUN All rights reserved *
 ******************************************************/

/**
 * Http接口
 * @author carlli
 * @encode utf-8
 * @version 1.0
 * @data 2012.9.24
 * @modify
 * -------------------------------------------------------------------
 * 
 * -------------------------------------------------------------------
 * @usage
 * -------------------------------------------------------------------
 *
 * -------------------------------------------------------------------
 */
Smart.define("http", function(S){    
    var G_CONST_PAGE_START = "PAGE-START";  //页面片段开始位置标识 <!--[PAGE-START]-->
    var G_CONST_PAGE_END = "PAGE-END";      //页面片段结束位置标识 <!--[PAGE-END]-->
    var G_LOADER_MAP = null;      // PageLoader实例MAP
    var G_CLICK_EVENT = "click";
    
    /**
     * 获取PageLoader实例
     * @param String name 实例名称
     * @param Boolean create 在不存在时是否创建新的一个新的实例
     * @return PageLoader loader
     */
    function GetPageLoader(name, create){
        var instance = null;
        G_LOADER_MAP = G_LOADER_MAP || {};
        if(true === create){
            if(!G_LOADER_MAP[name]){
                instance = G_LOADER_MAP[name] = new _PageLoader(name);
            }else{
                instance = G_LOADER_MAP[name];
            }
        }else{
            instance = (G_LOADER_MAP[name] || null);
        }
        return instance;
    };
    
    /**
     * 页面加载器（构造函数）
     * @param String name
     */
    var _PageLoader = function(name){
        this.name = name;               //名称，唯一标识
        this.useCache = false;          //设置AJAX请求时是否缓存
        this.withCredentials = false;   //设置使用用户凭证，为false时将在响应中忽略cookie
        this.target = null;             //当前调用的事件源        
        //--------------------------------------------
        this.on = {
            onprogress : null,      //处理过程中的回调，{Function callback, Array args, Object context}
            oncomplate : null,      //请求完成的回调，{Function callback, Array args, Object context}
            onsuccess : null,       //成功回调{Function callback, Array args, Object context}
            onerror : null,         //失败(JS异常)回调{Function callback, Array args, Object context}
            onneterror : null,      //网络失败回调{Function callback, Array args, Object context}
            onstart : null,         //请求开始时回调{Function callback, Array args, Object context}
            onend : null,           //请求结束时回调{Function callback, Array args, Object context}
            onback : null,          //回退时回调{Function callback, Array args, Object context}
            onscriptsuccess : null, //脚本加载成功回调{Function callback, Array args, Object context}
            onscripterror : null,   //脚本加载失败回调{Function callback, Array args, Object context}
            onbefore : null,        //发送请求前的回调{Function callback, Array args, Object context}
            onbeforecheck : null,   //发送请求前校验的回调，返回 true/false。{Function callback, Array args, Object context}
            onhistory : null,       //push历史记录时的回调{Function callback, Array args, Object context}
            onoffline : null,       //离线回调，返回 true/false。{Function callback, Array args, Object context}
            ononline : null,        //在线回调，返回 true/false。{Function callback, Array args, Object context}
            onhashcange : null,     //location.hash改变时回调{Function callback, Array args, Object context}
            onheader : null         //HTTP头交互回调{Function callback, Array args, Object context}
        };
    };
    //方法
    _PageLoader.prototype = {
        /**
         * 设置调用的事件源节点
         * @param Node target 源节点
         */
        setTarget : function(target){
            this.target = target;
        },
        /**
         * 获取调用的事件源节点
         */
        getTarget : function(){
            return this.target;
        },
        /**
         * 设置是否使用缓存
         * @param Boolean use
         */
        setUseCache : function(use){
            this.useCache = (true === use);
        },
        /**
         * 获取是否使用缓存
         * @return Boolean true/false
         */
        getUseCache : function(){
            return this.useCache;
        },
        /**
         * 设置用户凭证标识
         * @param Boolean _with
         */
        setWithCredentials : function(_with){
            //跟Access-Control-Allow-Credentials头匹配使用
            this.withCredentials = (true === _with);
        },
        /**
         * 获取用户凭证标识
         */
        getWithCredentials : function(){
            return this.withCredentials;
        },
        /**
         * 替换历史栈
         * @param String data 数据参数
         * @param String method 请求方法
         * @param String title 标题
         * @param String url URL
         * @param String mainKey 主键标识
         */
        replaceHistoryStack : function(data, method, title, url, mainKey){
            if("replaceState" in window.history){
                window.history.replaceState(data, document.title, url);
            }else{
                this.replaceHashStack(data, url, method, mainKey);
            }
        },
        /**
         * 解析hash栈
         * @param String _hash
         * @return Object {String request, String other}
         */
        parseHashStack : function(_hash){
            var hash = (_hash || location.hash).substr(1);
            var p = /`([^`]+)`/;
            var r = null;
            var o = {request:"", other:hash};

            if(null != (r = p.exec(hash))){
                o.request = r[1]||"";
                o.other = hash.replace(p, "");
            }
            p = null;
            return o;
        },
        /**
         * 解析hash值
         * @param String _hash
         * @return Object {String mainKey, String method, String data, String url}
         */
        parseRequestHash : function(_hash){
            var hash = this.parseHashStack(_hash);
            var request = hash.request;
            var o = S.Request.toJSONObject("?" + request);

            hash = null;
            return o;
        },
        /**
         * 替换HASH
         * @param String data 数据
         * @param String url URL
         * @param String method 方法
         * @param String mainKey 主键
         */
        replaceHashStack : function(data, url, method, mainKey){
            var hash = this.parseHashStack();
            location.hash = hash.other +
                            "`mainKey=" + mainKey +
                            "&method=" + method +
                            "&data=" + S.Request.encode(data) +
                            "&url=" + S.Request.encode(url) + "`";

            hash = null;
        },
        /**
         * 设置回调
         * @param String type 类型
         * @param Function callback 回调
         * @param Array args 参数
         * @param Object context 上下文
         */
        set : function(type, callback, args, context){
            var key = "on" + type;
            var rvs = "|beforecheck|offline|online|";

            if(key in this.on){
                if(callback && (callback instanceof Function) && callback.apply){
                    this.on[key] = {
                        "callback" : callback,
                        "args" : args || [],
                        "context" : context || this,
                        "returnValue" : (rvs.indexOf("|"+type+"|") != -1)
                    };
                }else{
                    this.on[key] = null;
                }
            }
        },
        /**
         * 移除回调
         * @param String type 类型
         */
        remove : function(type){
            this.on["on" + type] = null;
        },
        /**
         * 获取回调
         * @param String type 类型
         * @return Object on
         */
        get : function(type){
            var key = "on" + type;
            var o = this.on;

            if(key in o){
                return o[key];
            }
            return null;
        },
        /**
         * 清除所有回调
         */
        clear : function(){
            for(var key in this.on){
                if(this.on.hasOwnProperty(key)){
                    this.remove(key.substr(2));
                }
            }
        },
        /**
         * 执行回调函数
         * @param String type 类型
         * @param Array args 消息
         * @return * result 返回值
         */
        execCallback : function(type, args){
            var o = this.get(type);
            var m = args || [];
            var a = [].concat(m);
            var result = undefined;

            if(o && o.callback){
                a = a.concat(o.args||[]);
                if(true === o.returnValue){
                    result = o.callback.apply((o.context||this), a);
                }else{
                    o.callback.apply((o.context||this), a);
                }
            }
            m = null; a = null;

            return result;
        },
        /**
         * 添加参数
         * @param String url  原URL
         * @param String param 参数
         * @return String url 新URL
         */
        append : function(url, param){
            if(param){
                return url += ((url.indexOf("?") != -1 ? "&" : "?") + param);
            }
            return url;
        },
        /**
         * 分割内容
         * @param String data 数据
         * @param String flag 标识
         * @return String content 内容
         */
        slice : function(data, flag){
            var stack = [];
            var p1 = new RegExp("(<!--\\[" + G_CONST_PAGE_START + flag + "\\]-->)");
            var p2 = new RegExp("(<!--\\[" + G_CONST_PAGE_END + flag + "\\]-->)");
            var r1 = null;
            var r2 = null;
            var s = (null != (r1 = p1.exec(data)) ? r1[1] : "");
            var e = (null != (r2 = p2.exec(data)) ? r2[1] : "");

            var sl = s.length;
            var el = e.length;
            var content = "";

            if(sl > 0 && el > 0){
                stack.push('<!--[' + G_CONST_PAGE_START + flag + ']-->');
                content = data.substring(data.indexOf(s) + sl, data.indexOf(e));
                stack.push(content);
                stack.push('<!--['  + G_CONST_PAGE_END  + flag + ']-->');

                content = stack.join('');
            }else{
                content = data;
            }

            p1 = null; p2 = null; r1 = null; r2 = null; s = null; e = null; sl = 0; el = 0; stack = null;

            return content;
        },
        /**
         * 设置HTML内容
         * @param String selector CSS选择器
         * @param String data 数据
         * @param String flag 标识
         */
        html : function(selector, data, flag){
            var o = S.Node.one(selector);
            if(null != o){
                o.innerHTML = this.slice(data, (flag||""));
            }
        },
        /**
         * 修复HTML数据，用fixedSelector节点下的innerHTML填充targetSelector节点下内容
         * @param String targetSelector 目标CSS选择器
         * @param String fixedSelector 用于修复数据时的CSS选择器
         * @param Boolean isClearFixed 是否在修复后清除fixedSelector节点下的innerHTML
         */
        fixedHtml : function(targetSelector, fixedSelector, isClearFixed){
            var target = S.Node.one(targetSelector);
            var fixed = S.Node.one(fixedSelector);
            var clear = (true === isClearFixed);

            if("" != fixed.innerHTML){
                target.innerHTML = fixed.innerHTML;
            }

            if(clear){
                fixed.innerHTML = "";
            }

            target = null; fixed = null;
        },
        /**
         * 获取XMLHttpRequest实例
         * @param XMLHttpRequest httpRequest
         */
        getHttpRequest : function(){
            var httpRequest = null;
            
            if("XMLHttpRequest" in window){
                httpRequest = new XMLHttpRequest();
            }else{
                try{
                    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                }catch(e2){
                    try{
                        httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
                    }catch (e3){
                        httpRequest = null;
                    }
                }
            }
            
            return httpRequest;
        },
        /**
         * 加载页面
         * @param String url 请求URL
         * @param String method 请求方式
         * @param String data 传输数据
         * @param String mainKey 主键标识
         * @param Boolean isPushState 是否推送到历史记录
         */
        sendRequest : function(url, method, data, mainKey, isPushState){
            var xhr = this.getHttpRequest();
            if(null != xhr){            
                var loader = GetPageLoader(this.name);            
                var isGET = (method.toLowerCase() == "get");

                url = (isGET ? loader.append(url, data) : url);
                data = (isGET ? "" : data);

                loader.execCallback("start", [mainKey]); //添加开始回调
                xhr.open(method, url, true);

                if("withCredentials" in xhr){
                    xhr.withCredentials = loader.getWithCredentials();
                }

                if(true !== loader.getUseCache()){
                    xhr.setRequestHeader("No-Cache","1");
                    xhr.setRequestHeader("Pragma","no-cache");
                    xhr.setRequestHeader("Cache-Control","no-cache");
                    xhr.setRequestHeader("Expires","0");
                    xhr.setRequestHeader("Last-Modified","Thu, 1 Jan 1970 00:00:00 GMT");
                    xhr.setRequestHeader("If-Modified-Since","-1");
                }
                xhr.setRequestHeader("X-Requested-With","XMLHttpRequest");
                
                /**
                 * 状态常量，IE不支持
                 * UNSENT              : 0,    //尚未初始化，发送前
                 * OPENED              : 1,    //已打开请求
                 * HEADERS_RECEIVED    : 2,    //HTTP头交互接收完成
                 * LOADING             : 3,    //加载响应内容中
                 * DONE                : 4     //完成响应加载        
                 */
                xhr.onreadystatechange = function(){
                    if(4 == xhr.readyState){
                        try{
                            loader.execCallback("end", [mainKey]); //添加结束回调
                            
                            if(S.UA.ie != 0 && (S.UA.ie < 8)){ //ie6, ie7
                                loader.execCallback("header", [xhr.status, xhr, mainKey]);
                            }
                            
                            if(304 == xhr.status || 302 == xhr.status || 200 === xhr.status || 0 === xhr.status){
                                if(true === isPushState){
                                    loader.replaceHistoryStack(data, method , loader.name, url, mainKey);
                                }
                                loader.execCallback("success", [xhr.responseText, mainKey]); //添加成功回调
                            }else{
                                loader.execCallback("neterror", [xhr.status, mainKey]); //添加网络错误回调
                            }
                        }catch(e){
                            loader.execCallback("error", [e.message, mainKey]); //添加异常回调
                        }
                        loader.execCallback("complate", [xhr.status, xhr.responseText, mainKey]);
                        xhr = null; loader.xhr = null;
                    }else{
                        loader.execCallback("progress", [xhr.readyState, mainKey]); //添加处理中回调
                        if(!(S.UA.ie != 0 && (S.UA.ie < 8))){ //ie8+, other
                            if(2 == xhr.readyState){
                                loader.execCallback("header", [xhr.status, xhr, mainKey]);
                            }
                        }
                    }
                };

                xhr.send(data);
            }else{
                loader.execCallback("error", ["create \"XMLHttpRequest\" failed", mainKey]); //添加异常回调
            }
        },
        /**
         * 发送
         * @param String url 请求URL
         * @param String method 请求方式
         * @param String data 传输数据
         * @param String mainKey 主键标识
         * @param Boolean isPushState 是否推送到历史记录
         */
        sendBefore : function(url, method, data, mainKey, isPushState){
            this.execCallback("before", [url, method, data, mainKey, isPushState]);
            this.sendRequest(url, method, data, mainKey, isPushState);
        },
        /**
         * 加载页面
         * @param String url 请求URL
         * @param String method 请求方式
         * @param String data 传输数据
         * @param String mainKey 主键标识
         * @param Boolean isPushState 是否推送到历史记录
         * @reutrn Boolean true/false
         */
        loadURL : function(url, method, data, mainKey, isPushState){
            var check = this.get("beforecheck");
            var offline = this.get("offline");
            var online = this.get("online");

            if(null != offline && true === offline.returnValue){
                if(true === this.execCallback("offline", [url, method, data, mainKey, isPushState])){
                    return false;
                }
            }

            if(null != check && true === check.returnValue){
                if(true !== this.execCallback("beforecheck", [url, method, data, mainKey, isPushState])){
                    return false;
                }
            }

            if(null != online && true === online.returnValue){
                if(true === this.execCallback("online", [url, method, data, mainKey, isPushState])){
                    this.sendBefore(url, method, data, mainKey, isPushState);
                    return true;
                }
            }else{
                this.sendBefore(url, method, data, mainKey, isPushState);
                return true;
            }

            this.execCallback("error", ["PageLoad.loadURL()::call error", mainKey]);

            return false;
        },
        /**
         * 从HASH里加载页面数据
         * @param Boolean isPushState 是否推送到历史记录
         */
        loadHash : function(isPushState){
            var hash = this.parseRequestHash();

            if(null != hash){
                this.loadURL(hash.url, hash.method, hash.data, hash.mainKey, isPushState);
            }

            hash = null;
        },
        /**
         * 获取请求数据
         * @param Node node
         * @return Object data {String url, String method, String data, Boolean pushState, Boolean useCache, String mainKey}
         */
        getRequestData : function(node){
            var url = node.getAttribute("href") || node.getAttribute("data-url");
            var method = node.getAttribute("data-method") || "get";
            var data = node.getAttribute("data-data") || "";
            var isPushState = ("0" !== node.getAttribute("data-push"));
            var cache = ("1" == node.getAttribute("data-cache"));
            var credentials = ("1" == node.getAttribute("data-credentials"));
            var mainKey = (node.getAttribute("data-main")||"");

            return {
                "url" : url,
                "method" : method,
                "data" : data,
                "pushState" : isPushState,
                "useCache" : cache,
                "withCredentials" : credentials,
                "mainKey" : mainKey
            };
        },
        /**
         * 调用loadURL方法
         * @param Node|String n 节点或css选择符
         */
        call : function(n){
            var node = S.Node.one(n);
            var req = this.getRequestData(node);

            this.setUseCache(req.useCache);
            this.setWithCredentials(req.withCredentials);
            this.loadURL(req.url, req.method, req.data, req.mainKey, req.pushState);
        },
        /**
         * 绑定的回调处理函数
         * @param HTMLEvent e
         */
        bindHandler : function(e){
            e.preventDefault();
            e.stopPropagation();

            var loader = GetPageLoader(this.getAttribute("data-loader"));
            loader.setTarget(this);
            loader.call(this);
        },
        /**
         * 阻止点击事件默认行为
         * @param Event e
         */
        preventClick : function(e){
            e.preventDefault();
            e.stopPropagation();
        },
        /**
         * 绑定（注意不要将all和bind方法混用）
         * <tag data-loader-event="event" data-loader="string" data-method="GET|POST" data-data="" data-push="1" data-url="url" data-cache="0" data-credentials="0"></tag>
         * data-loader := string   PageLoader的name，程序自动设置
         * data-method := get      请求方法
         * data-data   := ""       请求时发送的数据
         * data-push   := 1        是否push访问历史
         * data-url    := ""       请求URL，href优先
         * data-cache  := 0|1      是否启动缓存
         * data-credentials := 0|1 是否使用用户凭证标识
         * data-loader-event  := event    事件类型
         *
         * @param String selector CSS选择器
         */
        bind : function(selector){
            var o = S.Node.one(selector);
            var type = G_CLICK_EVENT;
            if(null != o){
                type  = o.getAttribute("data-loader-event") || type;
                o.setAttribute("data-loader", this.name);
                o.addEventListener(type, this.bindHandler, false);

                if("click" != type){
                    o.addEventListener("click", this.preventClick, false);
                }
            }
        },
        /**
         * 获取真实当前节点
         * @param Node currentNode 节点
         * @param Node refNode 参考节点
         * @return Node realCurrent 真实节点
         */
        getRealCurrent : function(currentNode, refNode){
            refNode = refNode || S.Node.one("body");

            if(currentNode && 1 === currentNode.nodeType && currentNode != refNode){
                if(currentNode.getAttribute("data-use-loader")){
                    return currentNode;
                }else{
                    var p = currentNode.parentNode;
                    if(p){
                        return this.getRealCurrent(p, refNode);
                    }else{
                        return currentNode;
                    }
                }
            }
            return currentNode;
        },
        /**
         * 绑定所有的回调处理函数
         * @param HTMLEvent e
         */
        allHandler : function(e){
            var loader = GetPageLoader(this.getAttribute("data-loader"));
            var cur = loader.getRealCurrent(e.target, this);
            
            if("1" == cur.getAttribute("data-use-loader")){
                e.preventDefault();

                loader.setTarget(cur);
                loader.call(cur);
            }
        },
        /**
         * 阻止点击事件默认行为
         * @param Event e
         */
        preventTargetClick : function(e){
            var loader = GetPageLoader(this.getAttribute("data-loader"));
            var cur = loader.getRealCurrent(e.target, this);

            if("1" == cur.getAttribute("data-use-loader")){
                e.preventDefault();
            }
        },
        /**
         * 多个数据源绑定（注意不要将all和bind方法混用）
         * <tag data-loader-event="event" data-loader="string">
         *   <tag data-use-loader="1" data-method="GET|POST" data-data="" data-push="1" data-url="url" data-cache="0" data-credentials="0"></tag>
         *   <tag data-use-loader="1" data-method="GET|POST" data-data="" data-push="1" data-url="url" data-cache="0" data-credentials="0"></tag>
         *   <tag data-use-loader="1" data-method="GET|POST" data-data="" data-push="1" data-url="url" data-cache="0" data-credentials="0"></tag>
         *   <tag data-use-loader="1" data-method="GET|POST" data-data="" data-push="1" data-url="url" data-cache="0" data-credentials="0"></tag>
         * </tag>
         * data-loader := string   PageLoader的name，程序自动设置
         * data-use-loader := 0    是否使用PageLoader接口请求
         * data-method := get      请求方法
         * data-data   := ""       请求时发送的数据
         * data-push   := 1        是否push访问历史
         * data-url    := ""       请求URL，href优先
         * data-cache  := 0|1      是否启动缓存
         * data-credentials := 0|1 是否使用用户凭证标识
         * data-loader-event  := event    事件类型
         *
         * @param String selector CSS选择器(父级)
         */
        all : function(containerSelector){
            var o = S.Node.one(containerSelector);
            var type = G_CLICK_EVENT;

            if(null != o){
                type  = o.getAttribute("data-loader-event") || type;
                o.setAttribute("data-loader", this.name);
                o.addEventListener(type, this.allHandler, false);

                if("click" != type){
                    o.addEventListener("click", this.preventTargetClick, false);
                }
            }
        },
        /**
         * 移除script
         * @param Node head
         * @param Node script
         */
        removeScript : function(head, script){
            setTimeout(function(){
                head.removeChild(script);
                head = null;
                script = null;
            }, 200);
        },
        /**
         * 加载脚本
         * @param String url JS地址
         * @param String charset 编码
         */
        loadScript : function(url, charset){
            var script = document.createElement("script");
            var head = S.Node.one("head");
            var instance = GetPageLoader(this.name);
            var eventType = (undefined !== script.onreadystatechange && undefined !== script.readyState) ? "readystatechange" : "load";
            
            script = document.createElement("script");
            script.charset = charset || "utf-8";
            script.async = true;
            script.src = url;
            
            S.Event.on(script, eventType, function(e){
                instance.execCallback("scriptsuccess", [e]);
                instance.removeScript(head, script);
                head = null; script = null; instance = null;
            }, false);
            S.Event.on(script, "error", function(e){
                instance.execCallback("scripterror", [e]);
                instance.removeScript(head, script);
                head = null; script = null; instance = null;
            }, false);
            head.appendChild(script);
        },
        /**
         * 销毁
         */
        destory : function(){
            G_LOADER_MAP[this.name] = null;
        }
    }; //end _PageLoader
    
    var __http = {
        /**
         * 获取PageLoader实例
         * @param String name 唯一标识
         * @return Object
         */
        "newInstance" : function(name){
            var instance = null;

            if(!name || typeof(name) != "string"){
                throw new Error("Illegal parameter! Smart.Http.newInstance(name)::name = " + name);
            }else{
                instance = GetPageLoader(name, true);

                //方法注册
                return {
                    /**
                     * 绑定（注意不要将all和bind方法混用）
                     * @see _PageLoader.bind(selector)
                     */
                    "bind" : function(selector){instance.bind(selector);},
                    /**
                     * 多个数据源绑定（注意不要将all和bind方法混用）
                     * @see _PageLoader.all(containerSelector)
                     */
                    "all" : function(containerSelector){instance.all(containerSelector);},
                    /**
                     * 调用loadURL方法
                     * @see _PageLoader.call(n)
                     */
                    "call" : function(n){instance.call(n);},
                    /**
                     * 加载页面
                     * @see _PageLoader.loadURL(url, method, data, mainKey, isPushState)
                     */
                    "loadURL" : function(url, method, data, mainKey, isPushState){instance.loadURL(url, method, data, mainKey, isPushState);},
                    /**
                     * 从HASH里加载页面数据
                     * @see _PageLoader.loadHash(isPushState)
                     */
                    "loadHash" : function(isPushState){instance.loadHash(isPushState)},
                    /**
                     * 解析hash值
                     * @see _PageLoader.parseRequestHash(_hash)
                     */
                    "parseRequestHash" : function(_hash){return instance.parseRequestHash(_hash)},
                    /**
                     * 设置HTML内容
                     * @see _PageLoader.html(selector, data, flag)
                     */
                    "html" : function(selector, data, flag){instance.html(selector, data, flag);},
                    /**
                     * 修复HTML数据，用fixedSelector节点下的innerHTML填充targetSelector节点下内容
                     * @see _PageLoader.fixedHtml(targetSelector, fixedSelector, isClearFixed)
                     */
                    "fixedHtml" : function(targetSelector, fixedSelector, isClearFixed){instance.fixedHtml(targetSelector, fixedSelector, isClearFixed);},
                    /**
                     * 加载脚本
                     * @see _PageLoader.loadScript(url, charset)
                     */
                    "loadScript" : function(url, charset){instance.loadScript(url, charset);},
                    /**
                     * 设置回调
                     * @see _PageLoader.set(type, callback, args, context)
                     */
                    "set" : function(type, callback, args, context){instance.set(type, callback, args, context);},
                    /**
                     * 获取回调
                     * @see _PageLoader.get(type)
                     */
                    "get" : function(type){return instance.get(type);},
                    /**
                     * 移除回调
                     * @see _PageLoader.remove(type)
                     */
                    "remove" : function(type){instance.remove(type);},
                    /**
                     * 清除所有回调
                     * @see _PageLoader.clear()
                     */
                    "clear" : function(){instance.clear();},
                    /**
                     * 设置是否使用缓存
                     * @see _PageLoader.setUseCache(use)
                     */
                    "setUseCache" : function(use){instance.setUseCache(use);},
                    /**
                     * 设置用户凭证标识
                     * @see _PageLoader.setWithCredentials(_with)
                     */
                    "setWithCredentials" : function(_with){instance.setWithCredentials(_with);},
                    /**
                     * 获取当前的事件源节点
                     * @see _PageLoader.getTarget()
                     */
                    "getTarget" : function(){return instance.getTarget()},
                    /**
                     * 销毁PageLoader实例
                     * @see _PageLoader.destory()
                     */
                    "destory" : function(){instance.destory();}
                };
            }
        }
    };
    
    S.source("Http", __http);
});
 